﻿<!DOCTYPE html>
<html>

<head>
	<title></title>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<link rel="stylesheet" href="assets/css/bootstrap.min.css">
</head>

<body>
	<div class="wrapper" style="padding: 10px;">
		<div class="content-main">
			<h3 class="text-center">管理员账号申请</h3>
			<div id="wechatUser" class="text-center">
				<img src="assets/images/avatar.jpg" alt="" class="img-circle" width="60" height="60">
				<h4>微信昵称</h4>
			</div>
			<div id="apply" style="display: none;">
				<form id="applyForm">
					<div class="form-group">
						<label for="username">登录用户名</label>
						<input type="text" class="form-control" id="username" name="username" placeholder="请输入登录用户名"
							autocomplete="off">
						<p class="help-block">此名称不允许修改，请谨慎填写。格式为字母开头，且只可包含字母、数字、下划线（_），长度5-20位。</p>
					</div>
					<div class="form-group">
						<label for="password">登录密码</label>
						<input type="password" class="form-control" id="password" name="password" placeholder="请输入登录密码"
							autocomplete="off">
						<p class="help-block">密码必须包含大写字母、小写字母、数字，且长度8-20位。</p>
					</div>
					<div class="form-group">
						<label for="again_password">重复密码</label>
						<input type="password" class="form-control" id="again_password" name="again_password"
							placeholder="请再次输入密码" autocomplete="off">
						<p class="help-block">请重复输入新密码，以确认没有输入失误。</p>
					</div>
					<button type="submit" class="btn btn-primary btn-lg btn-block" id="btnSubmit">提交申请</button>
					<button type="button" class="btn btn-default btn-lg btn-block" id="refresh">刷新缓存</button>
				</form>
			</div>
			<div id="applied" style="display: none;">
				<p style="text-align: center; font-size: 18px; margin-top: 30px;">您的申请已提交，请耐心等候审核完成。</p>
			</div>
			<div id="passed" style="display: none;">
				<p style="text-align: center; font-size: 18px; margin-top: 30px;">您的申请已通过，请打开电脑端后台登录页面，即可扫码登录，或者通过申请时填写的账号密码登录。</p>
			</div>
		</div>
	</div>
	<script src="assets/js/jquery-1.8.1.min.js"></script>
	<script src="assets/js/jquery.cookie.js"></script>
	<script src="assets/js/bootstrap.min.js"></script>
	<script src="assets/js/common.js"></script>
	<script type="text/javascript">
		httpRequest("/wechat/Admin/getApplyInfo", {}, function (data) {
			$('#wechatUser img').attr('src', data.headimgurl);
			$('#wechatUser h4').html(data.nickname);
			if (data.applied) {
				if (data.passed) {
					$('#passed').show();
				} else {
					$('#applied').show();
				}
			} else {
				$('#apply').show();
			}
		});
		$("#refresh").click(function () {
			httpRequest("/wechat/Admin/refresh", {});
		});
		$('#applyForm').on('submit', function (e) {
			var data = {};
			$.each($(this).serializeArray(), function (index, item) {
				data[item.name] = item.value;
			});
			if (!data.username) {
				alert('请输入登录用户名！');
				e.preventDefault();
				return;
			}
			if (!data.password) {
				alert('请输入登录密码！');
				e.preventDefault();
				return;
			}
			if (data.password != data.again_password) {
				alert('两次输入密码不一致！');
				e.preventDefault();
				return;
			}
			httpRequest("/wechat/Admin/apply", data, function (data) {
				alert('提交成功！');
				location.reload();
			});
			e.preventDefault();
			return false;
		});
		$('#wechatUser img').on('error', function () {
			$(this).attr('src', 'assets/images/avatar.jpg');
			$(this).unbind("error");
		});
	</script>
</body>

</html>